package com.circle.interests.biz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.circle.common.core.utils.R;
import com.circle.common.core.validator.AddGroup;
import com.circle.common.core.validator.UpdateGroup;
import com.circle.interests.biz.entity.PrizeCategory;
import com.circle.interests.biz.request.PrizeCategoryPageRequest;
import com.circle.interests.biz.request.PrizeCategoryRequest;
import com.circle.interests.biz.service.IPrizeCategoryService;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zhou
 * @date 2021/12/5
 */
@Slf4j
@Api(tags = {"奖品分类管理（pc端接口）"})
@RestController
@RequestMapping("prizeCategory")
@ApiSupport(author = "周福寿")
public class PrizeCategoryController {

    @Resource
    private IPrizeCategoryService prizeCategoryService;

    @ApiOperation("新增")
    @PostMapping("/add")
    public R<?> add(@Validated({AddGroup.class}) @RequestBody PrizeCategoryRequest actCategoryRequest) {
        prizeCategoryService.add(actCategoryRequest);
        return R.success();
    }

    @ApiOperation("详情")
    @PostMapping("/info/{id}")
    public R<PrizeCategory> info(@ApiParam("活动分类ID") @PathVariable Long id) {
        return R.success(prizeCategoryService.getById(id));
    }

    @ApiOperation("编辑")
    @PostMapping("/update")
    public R<?> update(@Validated({UpdateGroup.class}) @RequestBody PrizeCategoryRequest actCategoryRequest) {
        prizeCategoryService.updateById(actCategoryRequest);
        return R.success();
    }

    @ApiOperation("删除")
    @PostMapping("/del/{id}")
    public R<?> del(@ApiParam("活动分类ID") @PathVariable Long id) {
        prizeCategoryService.deleteById(id);
        return R.success();
    }

    @ApiOperation("列表")
    @PostMapping("/list")
    public R<List<PrizeCategory>> list() {
        return R.success(prizeCategoryService.list(Wrappers.lambdaQuery(PrizeCategory.class).orderByDesc(PrizeCategory::getId)));
    }

    @ApiOperation("分页")
    @PostMapping("/page")
    public R<IPage<PrizeCategory>> page(@Validated @RequestBody PrizeCategoryPageRequest actCategoryPageRequest) {
        return R.success(prizeCategoryService.page(actCategoryPageRequest));
    }
}
